﻿using System;
using System.Configuration;
using NHibernate;
using System.Data;
using System.Collections;


namespace DAL
{
    class BaseDAL
    {
        public virtual Object save(Object o)
        {
            return DALProxy.doHibernateProxy(getSession(), "Save", o);
        }

        public virtual void update(Object o)
        {
            DALProxy.doHibernateProxy(getSession(), "Update", o);
        }

        public virtual void delete(Object o)
        {
            DALProxy.doHibernateProxy(getSession(), "Delete", o);
        }

        public virtual Object get(Type objectClass, Object id)
        {
            return DALProxy.doHibernateProxy(getSession(), "Get", objectClass, id);
        }

        public virtual IList executeHql(String hql, params Object[] parameters)
        {
            return DALProxy.doExecuteHql(getSession(), hql, parameters);
        }

        public virtual int executeUpdateHql(String hql, params Object[] parameters)
        {
            return DALProxy.doUpdateHql(getSession(), hql, parameters);
        }

        public virtual DataTable executeSql(String sql, params Object[] parameters)
        {
            return DALProxy.doExecuteSql(ConfigurationManager.ConnectionStrings["ConnString"].ToString(), sql, parameters);
        }

        protected ISession getSession()
        {
            return HibernateSessionFactory.getSession();
        }

        protected void closeSession()
        {
            HibernateSessionFactory.closeSession();
        }
    }
}
